package com.javasm.springmybatis.task;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

@Component
public class TestTask {

    @Async("asyncServiceExecutor")
    public void task1(){
        System.out.println("测试一个没有返回值的任务1");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("测试一个没有返回值的任务2");
    }

    @Async("asyncServiceExecutor")
    public Future<String> task2(){
        System.out.println("测试一个有返回值的任务2");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return new AsyncResult<>(Thread.currentThread().getName()+"wwww");
    }
}
